package Com.HupochuanAdmin.Dal.Tab;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import Com.Hupochuan.Dal.DBManager.DBManager;
import Com.Hupochuan.Vo.FlipPanel;

public class FlipPanelTab {
	/*
	 * 本类私有对象
	 */
	private DBManager<FlipPanel> dbManager = new DBManager<FlipPanel>(FlipPanel.class);
	
	/*
	 * 单一实例
	 */
	private FlipPanelTab(){}
	private static FlipPanelTab flipPanelTab = new FlipPanelTab();
	public static FlipPanelTab getObject(){
		return flipPanelTab;
	}
	
	/*
	 * 根据ID 更新数据
	 */
	public int updateData(String logoPath,long id){
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" update FlipPanel set ");
		sqlBuff.append(" logoPath=${logoPath}, ");
		sqlBuff.append(" updateTime=now() ");
		sqlBuff.append(" where id=${id} ");
		
		//sql参数部分
		paraHash.put("logoPath",logoPath);
		paraHash.put("id",id);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 根据ID 更新数据
	 */
	public int updateData(String name,String color,String url,float weight,long id){
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" update FlipPanel set ");
		sqlBuff.append(" 	name=${name}, ");
		sqlBuff.append(" 	color=${color}, ");
		sqlBuff.append(" 	url=${url}, ");
		sqlBuff.append(" 	weight=${weight}, ");
		sqlBuff.append(" 	updateTime=now() ");
		sqlBuff.append(" where id=${id} and ( ");
		sqlBuff.append(" 	name!=${name} ");
		sqlBuff.append(" 	or color!=${color} ");
		sqlBuff.append(" 	or url!=${url} ");
		sqlBuff.append(" 	or weight!=${weight} ");
		sqlBuff.append(" ) ");
		
		//sql参数部分
		paraHash.put("name",name);
		paraHash.put("color",color);
		paraHash.put("url",url);
		paraHash.put("weight",weight);
		paraHash.put("id",id);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 查询翻盖面板列表
	 */
	public List<FlipPanel> findFlipPanelList(){
		
		//参数部分
		List<FlipPanel> flipPanelList = new Vector<FlipPanel>();
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select * from FlipPanel order by weight desc,id ");
		
		//执行sql 
		flipPanelList = this.dbManager.querySqlReturnVoList(sqlBuff.toString(),paraHash);
		
		//返回列表
		return flipPanelList;
	}
	
	/*
	 * 获得翻盖面板对象
	 */
	public FlipPanel findFlipPanel(long id){
		//参数部分
		FlipPanel flipPanel = null;
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select * from FlipPanel where id=${id} ");
		
		//sql参数部分
		paraHash.put("id",id);

		//执行sql
		flipPanel = dbManager.querySqlReturnVo(sqlBuff.toString(), paraHash);
		
		//返回
		return flipPanel;
	}
}
